﻿@using Microsoft.AspNetCore.Mvc.Controllers
@using Nop.Services.Authentication.External
@using Nop.Services.Authentication.MultiFactor
@using Nop.Services.Catalog
@using Nop.Services.Cms
@using Nop.Services.Payments
@using Nop.Services.Plugins
@using Nop.Services.Shipping
@using Nop.Services.Shipping.Pickup
@using Nop.Services.Tax
@inject IPluginService pluginService
@{
    var plugin = pluginService.FindPluginByTypeInAssembly((ViewContext.ActionDescriptor as ControllerActionDescriptor).ControllerTypeInfo);

    //friendly name
    var friendlyName = plugin?.PluginDescriptor.FriendlyName;

    var activeMenuSystemName = string.Empty;
    var configureLocale = string.Empty;
    var backToLocale = string.Empty;
    var listActionMethodName = string.Empty;
    var listControllerName = string.Empty;

    if (plugin is IPaymentMethod)
    {
        //payment plugin
        activeMenuSystemName = "Payment methods";
        configureLocale = "Admin.Configuration.Payment.Methods.Configure";
        backToLocale = "Admin.Configuration.Payment.Methods.BackToList";
        listActionMethodName = "PaymentMethods";
        listControllerName = "Payment";
    }
    else if (plugin is IShippingRateComputationMethod)
    {
        //shipping rate computation method
        activeMenuSystemName = "Shipping providers";
        configureLocale = "Admin.Configuration.Shipping.Providers.Configure";
        backToLocale = "Admin.Configuration.Shipping.Providers.BackToList";
        listActionMethodName = "Providers";
        listControllerName = "Shipping";
    }
    else if (plugin is IPickupPointProvider)
    {
        //pickup point provider
        activeMenuSystemName = "Pickup points";
        configureLocale = "Admin.Configuration.Shipping.PickupPointProviders.Configure";
        backToLocale = "Admin.Configuration.Shipping.PickupPointProviders.BackToList";
        listActionMethodName = "PickupPointProviders";
        listControllerName = "Shipping";
    }
    else if (plugin is ITaxProvider)
    {
        //tax provider
        activeMenuSystemName = "Tax providers";
        configureLocale = "Admin.Configuration.Tax.Providers.Configure";
        backToLocale = "Admin.Configuration.Tax.Providers.BackToList";
        listActionMethodName = "List";
        listControllerName = "Tax";
    }
    else if (plugin is IExternalAuthenticationMethod)
    {
        //external auth method
        activeMenuSystemName = "External authentication methods";
        configureLocale = "Admin.Configuration.Authentication.ExternalMethods.Configure";
        backToLocale = "Admin.Configuration.Authentication.ExternalMethods.BackToList";
        listActionMethodName = "ExternalMethods";
        listControllerName = "Authentication";
    }
    else if (plugin is IMultiFactorAuthenticationMethod)
    {
        //multi-factor authentication method
        activeMenuSystemName = "Multi-factor authentication methods";
        configureLocale = "Admin.Configuration.Authentication.MultiFactorMethods.Configure";
        backToLocale = "Admin.Configuration.Authentication.MultiFactorMethods.BackToList";
        listActionMethodName = "MultiFactorMethods";
        listControllerName = "Authentication";

    }
    else if (plugin is IWidgetPlugin widget && !widget.HideInWidgetList)
    {
        //widgets
        activeMenuSystemName = "Widgets";
        configureLocale = "Admin.ContentManagement.Widgets.Configure";
        backToLocale = "Admin.ContentManagement.Widgets.BackToList";
        listActionMethodName = "List";
        listControllerName = "Widget";
    }
    else if (plugin is IMiscPlugin)
    {
        //Misc plugins
        activeMenuSystemName = "Local plugins";
        configureLocale = "Admin.Configuration.Plugins.Misc.Configure";
        backToLocale = "Admin.Configuration.Plugins.Misc.BackToList";
        listActionMethodName = "List";
        listControllerName = "Plugin";
    }
    else if (plugin is ISearchProvider)
    {
        //search provider
        activeMenuSystemName = "Local plugins";
        configureLocale = "Admin.Configuration.Plugins.SearchProvider.Configure";
        backToLocale = "Admin.Configuration.Plugins.SearchProvider.BackToList";
        listActionMethodName = "List";
        listControllerName = "Plugin";
    }

    if (NopHtml.GetActiveMenuItemSystemName() is { } menuItem && !string.IsNullOrEmpty(menuItem))
        activeMenuSystemName = menuItem;

    Layout = "_AdminLayout";
    //page title
    ViewBag.PageTitle = T(configureLocale).Text + " - " + friendlyName;
    //active menu item (system name)
    NopHtml.SetActiveMenuItemSystemName(activeMenuSystemName);
}
<div class="content-header clearfix">
    <h1 class="float-left">
        @T(configureLocale) - @friendlyName
        <small>
            <i class="fas fa-arrow-circle-left"></i>
            <a asp-action="@listActionMethodName" asp-controller="@listControllerName">@T(backToLocale)</a>
        </small>
    </h1>
    <div class="float-right">
        &nbsp;
    </div>
</div>
<section class="content">
    <div class="container-fluid">
        <div class="form-horizontal">
            @RenderBody()
        </div>
    </div>
</section>
